﻿using System.Data.Entity;
using System.Data.Entity.Migrations;
using XRM.Security.DataAccess.Models;

namespace XRM.Security.DataAccess.Context
{
    public class MyContext : DbContext, IDbContext
    {
        private const string ConnectionString = "Name=AppConnectionString";

        public MyContext()
            : base(ConnectionString)
        {
            //Database.SetInitializer<MyContext>(new DropCreateDatabaseIfModelChanges<MyContext>());
            //Configuration.AutoDetectChangesEnabled = true;
            //Configuration.LazyLoadingEnabled = true;
            
            Database.SetInitializer<MyContext>(new MigrateDatabaseToLatestVersion<MyContext, Configuration>());
        }

        public MyContext(bool autoDetectChanges, bool lazyLoading) : base(ConnectionString)
        {
            Configuration.AutoDetectChangesEnabled = autoDetectChanges;
            Configuration.LazyLoadingEnabled = lazyLoading;
        }

        public void SetModified(object entity)
        {
            Entry(entity).State = EntityState.Modified;
        }
        
        public DbSet<SystemUser> SystemUsers { get; set; }
        public DbSet<Department> Departments { get; set; }
        public DbSet<DepartmentAddress> DepartmentAddresses { get; set; }
        public DbSet<SkziKind> SkziKinds { get; set; }
        public DbSet<SertificateFsb> SertificateFsbs { get; set; }
        public DbSet<SertificateFstk> SertificateFstks { get; set; }
        public DbSet<InfoSystem> InfoSystem { get; set; }
        public DbSet<InfoSystemFile> InfoSystemFile { get; set; }
        public DbSet<IdentityCenter> IdentityCenter { get; set; }
        public DbSet<IdentityCenterCert> IdentityCenterCert { get; set; }
        public DbSet<IdentityCenterInfoSystem> IdentityCenterInfoSystem { get; set; }
        public DbSet<WorkKind> WorkKind { get; set; }
        public DbSet<WorkKindParam> WorkKindParam { get; set; }
        public DbSet<WorkKindSpec> WorkKindSpec { get; set; }
        public DbSet<CertRegister> CertRegister { get; set; }
        public DbSet<CertRegisterInfoSystem> CertRegisterInfoSystem { get; set; }
        public DbSet<PC> PC { get; set; }
        public DbSet<PCSticker> PCSticker { get; set; }
        public DbSet<UserRegister> UserRegister { get; set; }
        public DbSet<UserPC> UserPC { get; set; }
        public DbSet<UserSkzi> UserSkzi { get; set; }
        public DbSet<UserHistory> UserHistory { get; set; }
        public DbSet<UserInfoSystem> UserInfoSystem { get; set; }

        public DbSet<Request> Request { get; set; }
        public DbSet<RequestWorkKind> RequestWorkKind { get; set; }
        public DbSet<RequestWorkKindParam> RequestWorkKindParam { get; set; }
        public DbSet<RequestWorkKindParamSpec> RequestWorkKindParamSpec { get; set; }
        public DbSet<RequestCert> RequestCert { get; set; }
        public DbSet<RequestCertInfoSystem> RequestCertInfoSystem { get; set; }

        public DbSet<Role> Roles { get; set; }
        public DbSet<RoleMember> RoleMembers { get; set; }
    }

    public sealed class Configuration : DbMigrationsConfiguration<MyContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = true;
        }

        protected override void Seed(MyContext context)
        {
           
        }
    }
}
